﻿/*----------------------------------------------------------------
// Copyright (C) 2011 
// 版权所有。 
//
// 文件名：Form2.cs
// 文件功能描述：
//
// 
// 创建标识：kenter 2011-10-19
// EMAIL:kenter1643@163.com
//
// 修改标识：
// 修改描述：
//
// 修改标识：
// 修改描述：
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using WeiBOAPI.Common;
using WeiBoUI.FormEx;
using WeiBoUI.Template;

namespace KKWeiBO
{
    [System.Runtime.InteropServices.ComVisibleAttribute(true)]
    public partial class PicShow : FormBase
    {
        
        public PicShow()
        {
            this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            webBrowser1.ScriptErrorsSuppressed = true; //禁用错误脚本提示
            webBrowser1.IsWebBrowserContextMenuEnabled = false; //禁用右键菜单
            webBrowser1.WebBrowserShortcutsEnabled = false; //禁用快捷键
            webBrowser1.ObjectForScripting = this;
        }


        public void LoadPic(string imageUrl)
        {
            this.StartPosition = FormStartPosition.Manual;
            this.TopMost = true;

            TplParse tplParse = new TplParse("./Template/PicShow.tpl");
            string code = tplParse.TplText;
            tplParse.SetMember("PicUrl", imageUrl, ref code);
            this.webBrowser1.DocumentText = code;
            this.Show();
        }

        private void PicShow_SizeChanged(object sender, EventArgs e)
        {
            webBrowser1.Width = this.Width - 22;
            webBrowser1.Height = this.Height - 50;
            webBrowser1.Location = new Point(12, 30);
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            HtmlElement htmlElement = webBrowser1.Document.All["pic"];
            if (htmlElement != null)
            {
                this.Width = Convert.ToInt32(htmlElement.GetAttribute("width")) + 22 + 30;
                this.Height = Convert.ToInt32(htmlElement.GetAttribute("Height")) + 50 + 30;
            }

            if (this.Height + this.Location.Y > Screen.PrimaryScreen.Bounds.Height)
            {
                this.webBrowser1.ScrollBarsEnabled = true;
                this.Height = Screen.PrimaryScreen.Bounds.Height - this.Location.Y;
            }

            if (this.Width + this.Location.X > Screen.PrimaryScreen.Bounds.Width)
            {
                this.webBrowser1.ScrollBarsEnabled = true;
                this.Width = Screen.PrimaryScreen.Bounds.Width - this.Location.X;
            }
        }
    }
}
